<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>首页</title>
    <link rel="stylesheet" href="resource/weuimin.css" />
    <script src="resource/jquery1.js"></script>
	<script src="resource/qrcode.js"></script>
	<script src="resource/jquerybarcode.js"></script>
	<script src="template/js/jquery.js"></script>
	<script src="resource/my.js"></script>
	<script src="script/api.js"></script>
	<script type="text/javascript" src="script/sha256.js"></script>
	<script type="text/javascript" src="script/aes.js"></script>
	<script type="text/javascript" charset="UTF-8" src="script/naes.js"></script>
	<script type="text/javascript" src="script/modeecb.js"></script>
	<script src="html/resource/md5.js"></script>
	<script type="text/javascript" src="script/constants.js"></script>
	<script type="text/javascript" src="script/tmd5.js"></script>
    <style>
    	body{
    	    margin: 0;
    	    background: #fff;
    	}
   a.btn {
    width: 60px;
    line-height: 25px;
    display: block;
    text-align: center;
    font-size: 12px;
    background: rgba(51,51,51,0.3);
    color: #fff;
    border-radius: 5px;
		}
   .num {
   width: 60px;
   height:25px;
   color: #0000FF
   }
   .keyboard{
	    position: fixed;
	    z-index: 5000;
	    width: 100%;
	    background-color: #f2f2f2;
	    text-align: center;
	    bottom: 0%;
	    overflow: hidden;
   }
   
   .payinfo{
	    position: fixed;
	    z-index: 5000;
	    width: 100%;
	    background-color: #f2f2f2;
	    text-align: center;
	    bottom: 30%;
	    margin: 0 auto;
	    overflow: hidden;
   }
   #cac{   
	    width:100%;
	    height:100%;
	    background: #ffffff;
	    margin:0 auto;
	}
	.c_show{
	    width:90%;
	    height:5%;
	    border:1px solid #EEE9E9;
	    line-height:5%;
	    text-align:right;
	    font-size:50px;
	    color:#000;
	    margin: 0 auto;
	}
	.s_text{
	    width: 100%;
	    height:5%;
	    border:none;
	    line-height:5%;
	    text-align:right;
	    font-size:50px;
	    color:#000;
	}
	#cac h2{    
	    font-size:16px;
	    color:#000;
	    font-weight:500;
	    padding:12px 0 12px 20px;
	    cursor:move;
	}
	.cancel{
	   background-color: #FF6347;
	   color: #ffffff;
	}
	.bkey{
	   background-color: #10AEFF;
	   color: #ffffff;
	}
    .ckey{
       width: 100%;
    }
    .ckey td{
        width:25%;
	    height:3%;
	    text-align:center;
	    line-height:400%;
	    font-size:18px;
	    cursor:pointer;
	    list-style:none;
	    border-top:1px solid #EEE9E9;
	    border-right:1px solid #EEE9E9;
    }
    .ckey td:active{
       background: #27a8fa;
	   color:#fff;
    }
    </style>
</head>
<body>
   <div style="position:fixed;top: 0;">
	<div style="background:url('image/tabBar/ibg.png');background-size:100%;height:200px;">
	 <div style="width: 100%;text-align: center;color: #000;height: 20px;line-height: 20px;font-size: 22px;font-weight: 800;color: #ffffff;padding-top:20px">
         金穗服务
       </div>
       <div style="margin: 0 auto;color: #000;height: 30px;line-height: 30px;color: #ffffff;display: table;margin-top: 10px;" onclick="hyqy();">
         <div style="float: left;width:25px;height:25px;"></div>
         <div style="float: left;" id="level"></div>
         <div style="float: left;width:25px;height:25px;"><img id="click" style="width:25px;display: none;" src="image/click.gif"/></div>
       </div> 
  
		<div style="margin-top:30px;float:left;width:33%;text-align: center;" tapmode="presshover" onclick="scanPay();">
		<div style="height:50px">
		<img style="width:35%;" src="image/tabBar/pay.png"/>
		</div>
		<div style="color: #fff;">
		扫一扫
		</div>
		</div>
		<div style="margin-top:30px;float:left;width:33%;text-align: center;" tapmode="presshover" onclick="showEwm1();">
		<div style="height:50px">
		<img style="width:35%;" src="image/tabBar/payment.png"/>
		</div>
		<div style="color: #fff;">
		付款
		</div>
		</div>
		<div style="margin-top:30px;float:left;width:33%;text-align: center;" tapmode="presshover" onclick="aggregate()">
		<div style="height:50px">
		<img style="width:35%;" src="image/tabBar/get.png"/>
		</div>
		<div style="color: #fff;">
		收款
		</div>
		</div>
	</div>	
	</div>
	<div style="height: 200px;">
	</div>
	<div style="display: table;margin-top: 5px;background: #F8F8FF;padding-bottom: 20px;" id="perService">
	   <div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="zcsh('101')">
		 <div><img style="width:40%" src="image/tabBar/zcsh.png"></div>
		 <div style="font-size: 12px;">职场生活</div>
		 </div>
		 <div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="loadSwfw()">
		  <div><img style="width:40%" src="image/tabBar/dzfp.png"></div>
		 <div style="font-size: 12px;">电子发票</div>
		 </div>
		 <div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="openJskp()">
		  <div><img style="width:40%" src="image/tabBar/invoice.png"></div>
		 <div style="font-size: 12px;">极速开票</div>
		 </div>
		 
		 <div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="hotelBook()">
		  	<div><img style="width:40%" src="image/hotelicon.png"></div>
		 	<div style="font-size: 12px;">四川商旅</div>
		 </div>
<!--         <div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="JinDun()">
		  <div><img style="width:40%" src="image/tabBar/jindun.png"></div>
		 <div style="font-size: 12px;">未带证入住申请</div>
		 </div>-->
	</div>
	
	<div style="display: table;margin-top: 5px;background: #F8F8FF;padding-bottom: 20px;width: 100%;" id="company">
		 <div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="comService()">
		  	<div><img style="width:40%" src="image/tabBar/company.png"></div>
			<div style="font-size: 12px;">企业服务</div>
		 </div>
		<!-- <div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="JZGService()">
		  	<div><img style="width:50%" src="image/tabBar/jzgly.png"></div>
		 	<div style="font-size: 12px;">九寨沟旅游</div>
		 </div>-->
	</div>
	
	<div style="overflow:auto;margin-top: 5px;background: #F8F8FF;padding-bottom: 20px;width: 100%;display: none;" id="person">
		 <div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="perService()">
		  <div><img style="width:40%" src="image/tabBar/person.png"></div>
		 <div style="font-size: 12px;">个人服务</div>
		 </div>
	</div>
	
	<div style="overflow:auto;margin-top: 5px;background: #F8F8FF;padding-bottom: 20px;width: 100%;display: none;" id="jzgBackTools">
		 <div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="JZGBackService()">
		  <div><img style="width:40%" src="image/tabBar/jzglyfh.png"></div>
		 <div style="font-size: 12px;">返回首页</div>
		 </div>
	</div>
	
<!--	<div style="overflow:auto;margin-top: 5px;background: #F8F8FF;padding-bottom: 20px;display: none;" id="jzgMainTools">
	    <div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="loadClgl()">
		  	<div><img style="width:40%" src="image/tabBar/clgl.png"></div>
		 	<div style="font-size: 12px;">车辆管理</div>
		</div>
	</div>-->
	<div style="overflow:auto;margin-top: 5px;background: #F8F8FF;padding-bottom: 20px;display: none;" id="comService">
	    <div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="taxService();">
		  	<div><img style="width:40%" src="image/tabBar/taxService.png"></div>
		 	<div style="font-size: 12px;">税务服务</div>
		</div>
	
<!--		<div style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="openHotelManage();">
		  	<div><img style="width:40%" src="image/hotel.png"></div>
		 	<div style="font-size: 12px;">客房管理</div>
		</div>-->
	  	<div id="shsk" style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);display: none;" onclick="shsk()">
		  	<div><img style="width:40%" src="image/tabBar/gathering.png"></div>
		 	<div style="font-size: 12px;">企业收款</div>
		</div>
		<div id="jscg" style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);display: none;" onclick="jscg()">
		  	<div><img style="width:40%" src="image/tabBar/jscg.png"></div>
		 	<div style="font-size: 12px;">金穗采购</div>
		</div>
		<div id="gongan" style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);display: none;" onclick="loadBmb()">
		  	<div><img style="width:40%" src="image/tabBar/gabmfw.png"></div>
		 	<div style="font-size: 12px;">公安便民服务</div>
		</div>
		<div id="lzyly" style="float:left;width:25%;text-align: center;padding-top: 20px;-webkit-tap-highlight-color: rgba(0,0,0,0);display: none;" onclick="yly()">
		  	<div><img style="width:40%" src="image/tabBar/gzyly.png"></div>
		 	<div style="font-size: 12px;">公安娱乐业</div>
		</div>
	</div>
	
	<div style="overflow:auto;margin-top: 5px;background: #F8F8FF;padding-bottom: 20px;position:relative;display: none;" id="taxService">
	     <div style="float:left;width:25%;text-align: center;position: absolute;top: 50%;transform: translateY(-50%);-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="backComService();">
		  <div><img style="width:25%" src="image/tabBar/goback.png"></div>
		 <div style="font-size: 12px;">返回</div>
		 </div>
	    <div style="float:left;width:25%;text-align: center;padding-top: 20px;margin-left: 25%;-webkit-tap-highlight-color: rgba(0,0,0,0);" onclick="newUserReg();">
		  <div><img style="width:40%" src="image/tabBar/userReg.png"></div>
		 <div style="font-size: 12px;">新户注册</div>
		 </div>
	</div>
    
	
		<div id="loadingToast" style="display:none;">
			<div class="weui-mask_transparent"></div>
			<div class="weui-toast">
				<i class="weui-loading weui-icon_toast"></i>
				<p class="weui-toast__content">数据加载中...</p>
			</div>
		</div>
		
		<div class="js_dialog" id="iosDialog1" style="opacity: 1;">
            <div class="weui-mask" id="zftc1" tapmode="presshover" style="display:none;" onclick="hidedialog();"></div>
              <div class="keyboard" id="zftc" style="display: none">
  <div id="cac">
        <table style="margin: 0 auto;">
           <tr><td>收款商户:</td><td id="payeeName"></td></tr>
        </table>
        <div style="width:100%;text-align: center;" id="payeeComments"></div>   
        <div style="height:40px;color: #000;font-size: 16px;text-align: center;width: 100%;">请输入金额</div>
        <div class="c_show">
        
            <input  class="s_text" value="0" id="result"/>
        </div>
        <div style="height:20px;"></div>
        <table class="ckey">
        <tr>
        <td tapmode="presshover" onclick="command(7);">7</td>
        <td tapmode="presshover" onclick="command(8);">8</td>
        <td tapmode="presshover" onclick="command(9);">9</td>
        <td class="bkey" tapmode="presshover" onclick="del('j')">←</td>
        </tr>
        <tr>
        <td tapmode="presshover" onclick="command(4);">4</td>
        <td tapmode="presshover" onclick="command(5);">5</td>
        <td tapmode="presshover" onclick="command(6);">6</td>
        <td class="bkey" tapmode="presshover" onclick="clearzero('j')">清空</td>
        </tr>
        <tr>
        <td tapmode="presshover" onclick="command(1);">1</td>
        <td tapmode="presshover" onclick="command(2);">2</td>
        <td tapmode="presshover" onclick="command(3);">3</td>
        <td class="bkey" tapmode="presshover" onclick="pay();">确定</td>
        </tr>
        <tr>
        <td tapmode="presshover" onclick="command(0);">0</td>
        <td tapmode="presshover" onclick="command('00');">00</td>
        <td tapmode="presshover" onclick="dot('.')">.</td>
        <td class="cancel" tapmode="presshover" onclick="cancel();">取消</td>
        </tr>
        </table>
          
    </div>
</div>
    <div class="payinfo" id="payinfo" style="display:none;">
      <div style="height:20px;"></div>
      <table style="margin: 0 auto;">
           <tr><td>收款商户:</td><td id="payeeCompany"></td></tr>
           <tr><td>支付金额:</td><td id="payMoney"></td></tr>
        </table>
        <div style="width:100%;text-align: center;margin-bottom: 20px;" id="Comments"></div> 
        <div style="width:60%;height:40px;background: #27a8fa;margin:0 auto;color:#fff;border-radius:5px;line-height: 40px;" tapmode="presshover" onclick="submitPayInfo();">确认支付</div>
        <div style="height:20px;"></div>
    </div>
</div>
</body>
<script type="text/javascript" src="script/api.js"></script>
<script type="text/javascript">
    var scanprmt = "";//主扫支付参数
    var time;
    var queryTime = 0;//查询支付结果次数
    var payTime = 0;
    //点击输入金额执行函数
    function command(num){  
        var str = $("#result").val();
        str = (str == "0" ? "":str);
        str += num;
        $("#result").val(str);
    }
    
    function aggregate(){
        var login = $api.getStorage("LOGIN_FLAG");
        if (typeof(login) == "undefined") {
			abc();
			return;
		}
        api.openWin({
			name: 'aggregate',
			url: './html/CollectionMoney/main.html'
//			url: './html/jhzf/storeInfo.html'
//			url: './html/jhzf/myStore.html'
		});
    }
    
    function JinDun(){
        var login = $api.getStorage("LOGIN_FLAG");
        if (typeof(login) == "undefined") {
			abc();
			return;
		}
        api.openWin({
			name: 'noCerfCeckIn',
			url: './html/wzsh/index.html'
		});
    }
    
    function clearzero(){   
        $("#result").val(0);
    }
    
	function del(m){
	        var str = $("#result").val();
	        str = str.substring(0,str.length - 1);
	        str = (str == "" ? 0 : str);
	       $("#result").val(str);
    }
    function dot(m){
	        var str = $("#result").val();
	        if(str.length!=0){
	        str = str+m
	        }
	       
	       $("#result").val(str);
    }
    function cancel(){
         $("#zftc1").hide();
		 $("#zftc").hide();
		 clearzero('j');
    }
	
	function hidedialog(){
	    $("#zftc1").hide();
		$("#zftc").hide();
		$("#payinfo").hide();
	}
	
	function JZGService(){
		$("#perService").hide();
        $("#company").hide();
        $("#jzgBackTools").show();
        $("#jzgMainTools").show();
	}
	
	function JZGBackService(){
        $("#jzgBackTools").hide();
        $("#jzgMainTools").hide();
        $("#perService").show();
        $("#company").show();
	}
	//确认输入金额
	function pay(){
	    var je = $("#result").val();
        var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
        if (reg.test(je)) {
	        $("#zftc1").hide();
			$("#zftc").hide();
			judgePwd(je);
			clearzero('j');
	    }else{
	        alert("金额输入有误！");
	    };
	}
	
	//验证支付密码
	function judgePwd(je){
	    api.prompt({
		  	msg: '请输入六位支付密码',
		  	type: 'password',
		    buttons: ['确定', '取消']
		}, function(ret, err) {
		    var index = ret.buttonIndex;
		    var text = ret.text;
		    if(index==1){
		       var salt = api.loadSecureValue({
			       sync: true,
			       key: 'salt'
			  });
		      var passwd = md5(text);
		      var login = $api.getStorage("loginid");
			  passwd = md5(passwd+salt);
			  var phone = $api.getStorage("dl_phone");
			  var content = {"id":login,"zfpw":passwd,"phone":phone};
			  $("#loadingToast").show();
		      var callback = function(ret, err){
			       //console.log(JSON.stringify(ret));
			      $("#loadingToast").hide();
			      if(ret){
		                if(ret.flag=="Y"){
		                  completePay(je);
		        		}else{
		        		 api.alert({msg:'密码错误'});
		        		}
		
		        	}else{
		        		api.alert({msg:'网络异常'});
		        	}
			  }
			  encApiAjax(JSON.stringify(content),url.cxzfmm,callback);
		    }
		});
	}
	
	//完成支付
	function completePay(je){
	    $("#loadingToast").show();
	    var phone = $api.getStorage("dl_phone");
	    var ip = "";
	    var demo = api.require('ipAddress');
		demo.getIp({
		    isNetIp: true
		},function(ret, err) {
		    if(ret.status){
		      ip = ret.ip;
		    }
		    if(checkPayment(scanprmt)){
		        var data = eval("("+scanprmt+")");
		        var orderId = "";
		        if(typeof(data.orderId) != "undefined"){
		            orderId = data.orderId;
		        }
		        var payeeComments = "";
		        if(typeof(data.payeeComments) != "undefined"){
		            payeeComments = data.payeeComments;
		        }
		        var txnNo = "";
		        if(typeof(data.txnNo) != "undefined"){
		            txnNo = data.txnNo;
		        }
		        var cardId = "";
		        if(typeof(data.cardId) != "undefined"){
		            cardId = data.cardId;
		        }
		        var payeeName = "";
		        if(typeof(data.payeeName) != "undefined"){
		            payeeName = data.payeeName;
		        }
			    var callback = function(ret, err){
			        $("#loadingToast").hide();
			        if(ret.success == true){
			           $("#loadingToast").show();
			           time = setInterval("zfNotify('"+ret.id+"','"+ret.txnNo+"','"+ret.txnAmt+"')",2000);
			        }else{
			           api.alert({msg: ret.msg});
			        }
			    }
			    var content = {"phone":phone,"deviceId":api.deviceId,"orderId":orderId,"payeeComments":payeeComments,"txnAmt":je,"txnNo":txnNo,"sourceIp":ip,"cardId":cardId,"payeeName":payeeName};
			    apiAjax(JSON.stringify(content),url.payOrder,callback);
		    }
		});    
	}
	
	function checkPayment(payinfo){
	   var flag = true;
	   var paydata = eval("("+payinfo+")");
	   if(typeof(paydata.orderId) == "undefined"){
	       flag = false;
	   }
	   if(typeof(paydata.txnNo) == "undefined"){
	       flag = false;
	   }
	   return flag;
	}
    
    //查询结果
    function queryResult(id,txnNo,txnAmt){
        queryTime = 0;
        if(payTime >= 2){
           api.alert({msg: "由于网络原因暂时未接收到银联交易通知，请稍后在“银联二维码支付”-“历史纪录”中查询交易结果"});
           return;
        }
        var callback = function(ret, err){
	        if(ret){
	           $("#loadingToast").hide();
	           if(ret.result == "00"){
		          api.openWin({
		              name: 'scanPayResult',
		              url: './html/scanPayResult.html',
		              pageParam: {
							id:txnNo,
							amt:txnAmt,
							zt:1
					  }
	              });
	           }else if(typeof(ret.result) != undefined && ret.result != "00"){
	              var msgc = data.msg;
		          api.openWin({
		              name: 'scanPayResult',
		              url: 'html/scanPayResult.html',
		              pageParam: {
							msg:msgc,
							zt:2
					  }
	              });
	           }else{
	              $("#loadingToast").show();
	              time = setInterval("zfNotify('"+id+"','"+txnNo+"','"+txnAmt+"')",2000);
	           }
	        }
	    }
	    var content = {"txnNo":txnNo,"id":id,"txnAmt":txnAmt};
	    apiAjax(JSON.stringify(content),url.queryResult,callback);
	    payTime++;
    }
    
	//查询结果
	function zfNotify(id,txnNo,txnAmt){
	   if(queryTime == 2){
	        clearInterval(time);
	        queryResult(id,txnNo,txnAmt);
	   }else{
         var callback = function(data, err){
            if(data){
            $("#loadingToast").hide();
	        if (data.RESULT == "00") {	
	          clearInterval(time);
	          api.openWin({
	              name: 'scanPayResult',
	              url: './html/scanPayResult.html',
	              pageParam: {
						id:txnNo,
						amt:txnAmt,
						zt:1
				  }
              });
	        }else{
	          clearInterval(time);
	          var msgc = data.MSG;
	          api.openWin({
	              name: 'scanPayResult',
	              url: './html/scanPayResult.html',
	              pageParam: {
						msg:msgc,
						zt:2
				  }
              });
	        }
          }else{
            queryTime++;
          }
        }
        var content = {"payId":id,"txnNo":txnNo};
        apiAjax(JSON.stringify(content),url.queryPayResult,callback);
      }
  }
	
	//主扫    
    function scanPay(){
        payTime = 0;
        var login = $api.getStorage("LOGIN_FLAG");
		if (typeof(login) == "undefined") {
			abc();
			return;
		}
		$("#loadingToast").show();
		var dl_phone = $api.getStorage("dl_phone");
	    var content = {"phone":dl_phone};
		var callback = function(ret, err){
		    $("#loadingToast").hide();
            if(ret){
              if(JSON.stringify(ret) == "{}" || ret.pd == null || typeof(ret.pd.ZFPWZT) == "undefined"){
        		api.alert({msg:'还未设置支付密码'});
	        		api.openWin({
		                name: '个人信息',
		                url: 'html/userinfo_edit.html'
	                });
        	  }else{
        	    if(ret.pd.ZFPWZT=="1"){
        	        $("#loadingToast").show();
        	        var dl_phone = $api.getStorage("dl_phone");
					var cardId = '';
				    var callback = function(ret, err){
				        $("#loadingToast").hide();
			            if(ret){
			               if(ret.success == false){
			                  if(api.systemType=='ios'){
						        api.confirm({
						          title: '温馨提示',
						          msg:'对不起，您还没绑定银行卡，请先绑定银行卡！',
						          buttons: ['去绑卡', '暂时不用']
						        }, function(ret, err) {
						          var index = ret.buttonIndex;
						          if(index==1){
						            api.openWin({
				                        name: 'addCard',
				                        progress: {
								            type: "default",                //加载进度效果类型，默认值为 default，取值范围为 default|page，default 等同于 showProgress 参数效果；为 page 时，进度效果为仿浏览器类型，固定在页面的顶部
								            title: "",               //type 为 default 时显示的加载框标题
								            text: "加载中...",                //type 为 default 时显示的加载框内容
								            color: "#fff"                //type 为 page 时进度条的颜色，默认值为 #45C01A，支持#FFF，#FFFFFF，rgb(255,255,255)，rgba(255,255,255,1.0)等格式
								          },
				                        url: 'https://wechat.scjinsui.com/weixin/wx/unionPay/card_add.jsp?dlPhone='+dl_phone
			                        });
						          }else{
			                        //api.closeWin();
						          }
						        });
						      }else{
						        var r=confirm("您还没有绑卡哦，确定现在去绑卡吗？");
						        if(r){
						          api.openWin({
				                        name: 'addCard',
				                        progress: {
								            type: "default",                //加载进度效果类型，默认值为 default，取值范围为 default|page，default 等同于 showProgress 参数效果；为 page 时，进度效果为仿浏览器类型，固定在页面的顶部
								            title: "",               //type 为 default 时显示的加载框标题
								            text: "加载中...",                //type 为 default 时显示的加载框内容
								            color: "#fff"                //type 为 page 时进度条的颜色，默认值为 #45C01A，支持#FFF，#FFFFFF，rgb(255,255,255)，rgba(255,255,255,1.0)等格式
								          },
				                        url: 'https://wechat.scjinsui.com/weixin/wx/unionPay/card_add.jsp?dlPhone='+dl_phone
			                        });
						        }else{
						          //api.closeWin();
						        }
						      }
			               }else{
			                    $("#loadingToast").show();
			                    cardId = ret.cardId;
			                    var FNScanner = api.require('FNScanner');
						   		FNScanner.openScanner({
						   		    autorotation: true
						   		}, function(ret, err) {
						   		setTimeout(function(){
						   		       $("#loadingToast").hide();
						   		       if(ret){
							       		   if(ret.eventType == "success"){
							       		     $("#loadingToast").show();
						       		         var callback = function(ret, err){
										         console.log(JSON.stringify(ret));
										         $("#loadingToast").hide();
										         if(ret){
										         if(ret.success == true){
										            if(ret.flag == 0){//无金额
										       		   $("#zftc1").show();
											           $("#zftc").show();
											           $api.html($api.byId('payeeName'),ret.payeeName);
											           if(ret.hasOwnProperty("payeeComments")){
											              $api.html($api.byId('payeeComments'),ret.payeeComments);
											           }
											           ret.cardId = cardId;
											           scanprmt = JSON.stringify(ret);
											           console.log(scanprmt);
										            }else{//有金额
										               scanprmt = JSON.stringify(ret);
										               confirmPayInfo(ret);
										            }
										         }else{
										            api.alert({msg: ret.msg});
										         }
										         }else{
										           api.alert({msg: JSON.stringify(err)});
										         }
										     }
										     var content = {"qrNo":ret.content,"phone":dl_phone,"deviceId":api.deviceId};
										     apiAjax(JSON.stringify(content),url.queryOrder,callback);
							       		   }
						       		   }      
						           },500); 
						   		});
			               }
			            }else{
			               api.alert({msg: JSON.stringify(err)});
			            }
			        }
			        var content = {"phone":dl_phone};
			        apiAjax(JSON.stringify(content),url.getCardId,callback);
        		}else{
	        		api.alert({msg:'还未设置支付密码'});
	        		api.openWin({
		                name: '个人信息',
		                url: 'html/userinfo_edit.html'
	                });
	        	}
	          }
        	}else{
        		api.alert({msg:'网络异常'});
        	}
	    }
	    encApiAjax(JSON.stringify(content),url.zfmmzt,callback);
    }
    
    //有金额确认支付信息
    function confirmPayInfo(ret){
          $api.html($api.byId('payeeCompany'),ret.payeeName);
          $api.html($api.byId('payMoney'),ret.txnAmt+"元");
          if(ret.hasOwnProperty("payeeComments")){
              $api.html($api.byId('Comments'),ret.payeeComments);
          }
          $("#zftc1").show();
		  $("#payinfo").show();
    }
    
    //提交支付
    function submitPayInfo(){
         $("#zftc1").hide();
		 $("#payinfo").hide();
		 var data = eval("("+scanprmt+")");
         judgePwd(data.txnAmt);
    }
        
        //是否登录
        function seticon() {
			var login = $api.getStorage("LOGIN_FLAG");
			if (login == null || login == '' || login == 'undefined' || typeof(login) == "undefined") {
				$("#login_btn").show();
				$("#wdxx_btn").hide();
			} else {
				$("#login_btn").hide();
				$("#wdxx_btn").show();

			}
		}
        
        //银联
		function ylewmzf() {
			var login = $api.getStorage("LOGIN_FLAG");
			var dl_phone = $api.getStorage("dl_phone");
			if (typeof(login) == "undefined") {
				abc();
				return;
			}
			var op = $api.getStorage("openid");
			var s = api.connectionType;
			    if (s != 'none') {
			api.openWin({
				name: 'ylewmzf',
                progress:{
				    type:"default",                //加载进度效果类型，默认值为 default，取值范围为 default|page，default 等同于 showProgress 参数效果；为 page 时，进度效果为仿浏览器类型，固定在页面的顶部
				    title:"",               //type 为 default 时显示的加载框标题
				    text:"数据加载中...",                //type 为 default 时显示的加载框内容
				    color:"#FFF"                //type 为 page 时进度条的颜色，默认值为 #45C01A，支持#FFF，#FFFFFF，rgb(255,255,255)，rgba(255,255,255,1.0)等格式
				},	
				//url: 'http://192.168.76.36:8181/app/dlyz.do?phone='+dl_phone+'&passwd='+md5_passwd + '&deviceId=' + op
				url: url.ylurl+'?phone=' + dl_phone + '&deviceId=' + op

			});
			    } else {
			      $api.toast('提示', '网络异常', 2000);
			}
		}

        //职场生活
		function zcsh(dm) {
			SetCookie(dm, dm);
			api.openWin({
				name: 'main',
				url: 'html/zcsh/main.html',
				pageParam: {
					state: dm
				}
			});
		}
		
        
        //跳转登录
		function abc() {
			api.openWin({
				name: 'abc',
				url: 'html/login.html'
			});
		}

        //用户信息
		function bcd() {
			api.openWin({
				name: 'bcd',
				url: 'html/userinfo.html'
			});

		}

        //泸州娱乐业
		function yly(){
		      api.openWin({
			      name: 'jdyd1',
			      url: './html/lzyly/index.html'
		      });

		}

        //金穗采购
		function jscg() {
			$("#loadingToast").show();
			var openid=$api.getStorage("openid");
			var callback = function(ret, err){
			        setTimeout("$('#loadingToast').hide()",1000);
					if (ret) {
						if(ret.flag=='0'){
							//一般客户
							api.openWin({
								name: 'bgyp',
								url: 'html/jscg/jscg.html'
							}); 
						}
						else if (ret.flag=='1'){
							//旅馆客户
							api.openWin({
							    name: 'lgyp',
							    url: 'html/jscg/jdypMain.html'
							});
						}
						else{
							//其他，默认当作一般客户
							api.openWin({
								name: 'bgyp',
								url: 'html/jscg/jscg.html'
							});
						}
					}
		        }
		    var parameter = {"openid":openid};
		    apiAjax(JSON.stringify(parameter),url.cgurl,callback);
		}

        //
		function setClick(e, dm) {
			var note = e.parentNode.parentNode;
			if (getCookie(dm) != null) { //已经点击过的新品不要提示图标
				note.setAttribute("class", "weui-grid");
			}
		}

    //旅馆管理
    function openHotelManage() {
        if(typeof($api.getStorage("dl_phone")) == "undefined" || $api.getStorage("dl_phone") == "undefined" ){
            api.openWin({
	            name: 'login',
	            url: './html/login.html'
            });
        }else{
			api.openWin({
			    vScrollBarEnabled: false,
			    hScrollBarEnabled: false,
				name: 'HotelManage',
				url: 'html/HotelManage/main.html'
			});
		}
	}

    //银联二维码
	function showEwm1() {
		var login = $api.getStorage("LOGIN_FLAG");
		var dl_phone = $api.getStorage("dl_phone");
		if (typeof(login) == "undefined" || login == "undefined" || "" == login || login == null) {
			abc();
			return;
		}
		var ip = "0.0.0.0";
		var ipAddr = api.require('ipAddress');
		var s = api.connectionType;
	    if (s != 'none') {
        var demo = api.require('ipAddress');
		demo.getIp({
		    isNetIp: true
		},function(ret, err) {
		    if(ret.status){
		      ip = ret.ip;
		    }
					var aeskey = api.loadSecureValue({
 			          sync: true,
			          key: 'aeskey'
				    });
				    var salt = api.loadSecureValue({
				        sync: true,
				        key: 'salt'
				    });
					var content = {"dlPhone":dl_phone,"ip":ip,"deviceID":api.deviceId,"phone":dl_phone};
			        var sign = md5(JSON.stringify(content)+salt);
			        var p = {"sign":sign,"content":JSON.stringify(content)};
			        var para = Encrypt(JSON.stringify(p),aeskey);
			        para = para.replace(/\+/g,"%2B");
			        api.openWin({
					    progress:{
						    type:"default",                //加载进度效果类型，默认值为 default，取值范围为 default|page，default 等同于 showProgress 参数效果；为 page 时，进度效果为仿浏览器类型，固定在页面的顶部
						    title:"",               //type 为 default 时显示的加载框标题
						    text:"数据加载中...",                //type 为 default 时显示的加载框内容
						    color:"#FFF"                //type 为 page 时进度条的颜色，默认值为 #45C01A，支持#FFF，#FFFFFF，rgb(255,255,255)，rgba(255,255,255,1.0)等格式
						},
						name: 'ewm',
						url: url.ewmurl+'?para='+para
						
					});
          });
		} else {
			 $api.toast('提示', '网络异常', 2000);
	    }	

	}
    
    //保存定位
    function saveCoord(_phone,_position){
	    var callback = function(ret, err){
	            //console.log(JSON.stringify(ret));
	        }
	    var parameter = {"position":_position,"phone":_phone};
	    apiAjax(JSON.stringify(parameter),url.dwurl,callback);
	}
	
	var openid = '';
	window.apiready = function() {
	if(typeof($api.getStorage("passwordxx")) != "undefined"){
	  if($api.getStorage("passwordxx").indexOf("},{")>0){
	      var ww = eval("("+$api.getStorage("passwordxx")+")");
	      var w = '';
		  for (var i = 0 ; i < ww.length ; i++) {
	          w += ww[i].index + ww[i].index;
	      }
	      $api.setStorage($api.getStorage('dl_phone')+'CHART', md5(w));
	      $api.rmStorage("passwordxx");
	  }else{
		  var aeskey = api.loadSecureValue({
			   sync: true,
			   key: 'aeskey'
		  });
		  var pwd = Decrypt($api.getStorage("passwordxx"),aeskey);
		  var pp = eval("("+pwd+")");
		  var p = '';
		  for (var i = 0 ; i < pp.length ; i++) {
	          p += pp[i].index + pp[i].index;
	      }
	      $api.setStorage($api.getStorage('dl_phone')+'CHART', md5(p));
	      $api.rmStorage("passwordxx");
      }
	}
	api.parseTapmode();
	if($api.getStorage("cusInfo") == undefined){//旅馆未上报数据
		 var cusInfo = new Array();
	     $api.setStorage("cusInfo",cusInfo);
    }
	if(api.jailbreak){
	  alert("系统已root，请注意使用安全!");
	}
//指纹	
//	    var touchID = api.require('touchID');
//	    touchID.verify(
//	    function(ret, err) {
//	        if (ret.status) {
//	            api.alert({ msg: "验证通过" });
//	        } else {
//	            if (ret.code == 0) {
//	                api.alert({ msg: "用户选择手动输入" });
//	            } else if (ret.code == 1) {
//	                api.alert({ msg: "用户取消验证" });
//	            } else if (ret.code == 2) {
//	                api.alert({ msg: "验证三次失败" });
//	            } else if (ret.code == 3) {
//	                api.alert({ msg: "多长验证失败请锁定手机" });
//	            } else {
//	                api.alert({ msg: "验证失败，未知错误" });
//	            }
//	        }
//	    });
//	    if(api.systemType=='ios'){
//		 }else{
//		 	api.setScreenSecure({secure: true});
//		 }

	    openid = $api.getStorage("openid");
	    //监听退出app进入后台
        api.addEventListener({
		    name:'pause'
		}, function(ret, err){  
		var outtime = new Date().getTime();
		$api.setStorage("outTime",outtime); 
		});
		//监听app回到前台
		api.addEventListener({
		    name:'resume'
		}, function(ret, err){
		    var loginid = $api.getStorage("LOGIN_FLAG");
			var outtime = $api.getStorage("outTime");
			$api.setStorage("outTime","");
			if (typeof($api.getStorage("LOGIN_FLAG")) == "undefined") {

			} else {
	           var intime = parseInt(new Date().getTime())-parseInt(outtime);
	           if(intime > 300000){
		 	       zhuxiao();
			     }
			}      
		});
		//监听功能模块
		api.addEventListener({
			name: 'removeRoot'
		}, function(ret, err) {
			$api.setStorage("rootid", "");
		});
		//登录或修改功能模块后刷新主界面
		api.addEventListener({
			name: 'reloadIndex'
		}, function(ret, err) {
			loadWin();
		});
		//
		api.addEventListener({
			name: 'reloadRoot'
		}, function(ret, err) {
			loadWin();
		});
		//登录后判断手势密码
		api.addEventListener({
			name: 'chartLock'
		}, function(ret, err) {
		   setTimeout(function(){
		       if(typeof($api.getStorage($api.getStorage('dl_phone')+'CHART')) == "undefined"){
			    api.confirm({
			    title: '温馨提示',
    			msg:'是否立即设置手势密码',
   			 	buttons: ['设置','不设置']
                },function(ret,err){
                  if(ret){
                	if(ret.buttonIndex==1){
		   			 	api.openWin({
				          name: 'scLock',
				          url: 'html/setChartLock.html'
			          });
		   			 }else{
		   			   $api.setStorage("chartPwd",false);
		   			 }
		   		   }
                });
	          }
		   },500);
		});
		
          var loginid = $api.getStorage("LOGIN_FLAG");
		  if(api.systemType == 'ios' && $api.getStorage("lgtime") != "" && typeof($api.getStorage("lgtime")) != "undefined"){
		     if(loginid != "" && loginid != null && loginid != "undefined" && typeof(loginid) != "undefined"){
		        var lgtime = $api.getStorage("lgtime");
		        var difftime = parseInt(new Date().getTime()-parseInt(lgtime));
		        if(difftime > 300000){
		           //alert("会话已超时，请重新登录！");
			       $api.setStorage("lgtime","");
			       zhuxiao();
		        }
		     }
		   }
        loadWin();
	}

    function loadWin(){
     if("Y" == $api.getStorage("LOGIN_FLAG")){
     //console.log($api.getStorage("memberRight"));
	  if($api.getStorage("memberRight") != true && $api.getStorage("memberRight") != "true"){
        $("#click").show();
      }else{
        $("#click").hide();
      }
	  var YHDJ = $api.getStorage("YHDJ");
	  
            if (YHDJ == "平台会员") {
          	$("#level").html("（平台会员）");
            }else if(YHDJ=="白银会员"){
             $("#level").html("（白银单位会员）");
            }else if(YHDJ=="黄金会员"){
             $("#level").html("（黄金单位会员）");
            }else if(YHDJ=="铂金会员"){
             $("#level").html("（铂金单位会员）");
            }else if(YHDJ=="钻石会员"){
             $("#level").html("（钻石单位会员）");
            }else if(typeof(YHDJ) == "undefined" || YHDJ == "undefined"){
                var callback = function(ret, err){
			       if(typeof(ret.level) == "undefined" || ret.level == "undefined"){
	    			   YHDJ = "平台会员";
	    			}else{
	    			   YHDJ = res.level;
	    			}
	    			if (YHDJ == "平台会员") {
			          	$("#level").html("（平台会员）");
			            }else if(YHDJ=="白银会员"){
			             $("#level").html("（白银单位会员）");
			            }else if(YHDJ=="黄金会员"){
			             $("#level").html("（黄金单位会员）");
			            }else if(YHDJ=="铂金会员"){
			             $("#level").html("（铂金单位会员）");
			            }else if(YHDJ=="钻石会员"){
			             $("#level").html("（钻石单位会员）");
			            }
			    }
			    var content = {"phone":$api.getStorage("dl_phone")};
			    apiAjax(JSON.stringify(content),url.queryLevel,callback);
            }
	 }else{
	    $("#click").hide();
	 }
        var bMap = api.require('bMap');
		bMap.getLocationServices(function(ret, err) {
		    if (ret.enable) {
		       var bMap = api.require('bMap');
				bMap.getLocation({
				    accuracy: '100m',
				    autoStop: true,
				    filter: 1
				}, function(ret, err) {
				    if (ret.status) {
				        var position = ret.lon+","+ret.lat;
				        var phone = $api.getStorage("dl_phone");
				        if(phone != "undefined" && phone != "" && phone != null && typeof(phone) != "undefined"){
				          saveCoord(phone,position);
				        }
				    } 
				});
		    }
		});
        $api.setStorage("time", 1);
        //检查功能模块
        checkRoot();
		api.removeLaunchView();
		var header = $api.byId('jsheader_absolute');
		if (api.systemType == 'ios') {
			//$api.fixIos7Bar(header);
		} else {
			$api.fixStatusBar(header);
		}
		seticon();
        
    }
    
    //检查功能模块
	function checkRoot() {
        var out = $api.getStorage("outTime");
		var loginid = $api.getStorage("LOGIN_FLAG");	
		if (loginid = "" || loginid == null || loginid == "undefined" || typeof(loginid) == "undefined") {
			$("#gongan").hide();
			$("#jscg").hide();
			$("#lzyly").hide();
			$("#shsk").hide();
			$("#jzgly").hide();
		  if(parseInt($api.getStorage("chartWrong")) < 5 || typeof($api.getStorage("chartWrong")) == "undefined"){
			if(typeof($api.getStorage($api.getStorage('dl_phone')+'CHART')) != "undefined" && ($api.getStorage("chartPwd") == "true" || $api.getStorage("chartPwd") == true)){
	           api.openWin({
		          name: 'chartLock',
		          url: 'html/chartLock.html'
	           });
	        }
	      }
		} else {
			var re = $api.getStorage("rootid");
			if (re == null || re == 'undefined' || typeof(re) == 'undefined') {

			} else {
				if (re.indexOf("1") >= 0) {
					$("#gongan").show();
				} else {
					$("#gongan").hide();
				}
				if (re.indexOf("2") >= 0) {
					$("#jscg").show();
				} else {
					$("#jscg").hide();
				}
				 if (re.indexOf("3") >= 0) {
					$("#lzyly").show();
				} else {
					$("#lzyly").hide();
				}
				 if (re.indexOf("4") >= 0) {
					$("#shsk").show();
				} else {
					$("#shsk").hide();
				}
				if (re.indexOf("5") >= 0) {
					$("#hotelManage").show();
				} else {
					$("#hotelManage").hide();
				}
				if (re.indexOf("6") >= 0) {
					$("#jzgly").show();
				} else {
					$("#jzgly").hide();
				}
			}
	   }
	}

	function bak() {
		$("#jsheader").hide();
		var browser = api.require('webBrowser');
		browser.closeView();
	}

    //公安便民服务
	function loadBmb() {
		var phone = $api.getStorage("dl_phone");
		var s = api.connectionType;
	    if (s != 'none') {
	api.openWin({
			name: '公安服务',
			url: 'http://218.6.173.52:5001/weixin/wx/ybss/spmain.jsp?openid='+openid+"&phone="+phone,
			//url: 'http://192.168.85.42:8081/wx/ybss/login.jsp?openid='+openid+"&phone="+phone,
			progress: {
				type: "default", //加载进度效果类型，默认值为 default，取值范围为 default|page，default 等同于 showProgress 参数效果；为 page 时，进度效果为仿浏览器类型，固定在页面的顶部
				title: "", //type 为 default 时显示的加载框标题
				text: "", //type 为 default 时显示的加载框内容
				color: "" //type 为 page 时进度条的颜色，默认值为 #45C01A，支持#FFF，#FFFFFF，rgb(255,255,255)，rgba(255,255,255,1.0)等格式
			},
		});
	    } else {
      $api.toast('提示', '网络异常', 2000);
       }					
		
	}

	//车辆管理
	function loadClgl() {
		var jp = $api.getStorage("LOGIN_FLAG");
		if (jp == null || jp == '' || typeof(jp) == undefined || jp == 'undefined') {
			api.alert({
				msg: '请先登录！'
			}, function(ret, err) {
				api.openWin({
					name: '跳转登陆',
					url: 'html/login.html'
				});
			});
		} else {
		 	api.openWin({
					name: '车辆管理',
					url: 'html/clgl/selectRole.html'
			});
		}
	}
	
    //电子发票
	function loadSwfw() {
		var browser = api.require('webBrowser');
		browser.open({
			url: 'http://cloud.scjinsui.com:8083/InvoiceLookup/',
			progress: {
				color: "#45C01A"
			}
		});
		browser.historyBack(
			function(ret, err) {
				if (!ret.status) {
		            //api.closeWin();
		        }
		});
	}


	function scannerYl() {
		var dl_phone = $api.getStorage("LOGIN_FLAG")
		if (typeof(dl_phone) == "undefined") {
			abc();
			return;
		}
		var FNScanner = api.require('FNScanner');
		FNScanner.openScanner({
			autorotation: true
		}, function(ret, err) {

			if (ret.eventType == "success") {
				api.openWin({
					name: 'ylpay',
					url: './html/ylzf/ylpay.html',
					pageParam: {
						name: 'test'
					}
				});


			}
		});
	}

	function getRandomString(len) {
		len = len || 32;
		var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1
		var maxPos = $chars.length;
		var pwd = '';
		for (i = 0; i < len; i++) {
			pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
		}
		return pwd;
	}

	
    //极速开票
	function openJskp() {
		var jp = $api.getStorage("LOGIN_FLAG");
		if (jp == null || jp == '' || typeof(jp) == undefined || jp == 'undefined') {
			api.alert({
				msg: '请登录'
			}, function(ret, err) {
				api.openWin({
					name: '跳转登陆',
					url: 'html/login.html'
				});
			});
		} else {
		 api.openWin({
				name: 'jskp.html',
				url: 'html/yst/yst.html'
			});
		 }
	   }

	
	
	//商户收款
	function shsk(){
		api.openWin({
				name: 'lgyp',
				url: 'html/shsk/sk.html'
		});
    }
    //会员权益
    function hyqy(){
        $api.setStorage("memberRight",true);
        $("#click").hide();
		api.openWin({
				name: 'hyqy',
				url: 'html/hyxz.html'
		});
    }
    
    
    //注销
	function zhuxiao(){
	    $api.rmStorage("LOGIN_FLAG");
        $api.setStorage("lgtime","");
	    loadWin();
	}
	
	
    function comService(){
        $("#perService").hide();
        $("#company").hide();
        $("#comService").show();
        $("#person").show();
    }
    
    function perService(){
        $("#perService").show();
        $("#company").show();
        $("#comService").hide();
        $("#person").hide();
        $("#taxService").hide();
    }
    
    function backComService(){
        $("#comService").show();
        $("#taxService").hide();
    }
    
    function taxService(){
        $("#comService").hide();
        $("#taxService").show();
    }
    
    function newUserReg(){
        var jp = $api.getStorage("dl_phone");
		if (jp == "" || jp == null || jp == "undefined" || typeof(jp) == "undefined") {
			api.alert({
				msg: '请登录'
			}, function(ret, err) {
				api.openWin({
					name: '跳转登陆',
					url: 'html/login.html'
				});
			});
		}else{
			api.openWin({
			 name: '客户信息搜索',
			 url: 'html/xhzc/searchUserInfo.html'
			});
		}

    }
    
    function hotelBook(){
    	api.openWin({
	        name: 'my_hotel_info',
	        vScrollBarEnabled: false,
	        hScrollBarEnabled: false,
	        url: './html/jdyd/hotel_reserve_home.html'
        });
    }
</script>
</html>